package com.zm.spring.jdbc;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class MyServletContextListener implements ServletContextListener {
    AnnotationConfigApplicationContext cxt;
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("---------------contextInitialized-------------");
        cxt = new AnnotationConfigApplicationContext(JdbcConfig.class);
        servletContextEvent.getServletContext().setAttribute("cxt",cxt);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("---------------contextDestroyed-------------");
        cxt.close();
    }
}
